﻿using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace SharpScript
{
    public class ScriptBase : DynamicObject
    {
        
        #region DynamicObject Implementation
        // ####################################################################
        // ###### DynamicObject Implementation
        // ####################################################################

        // The inner dictionary which serves as our lookup table.
        protected Dictionary<string, Object> _dictionary;

        // If you try to get a value of a property 
        // not defined in the class, this method is called.
        public override bool TryGetMember(GetMemberBinder binder, out dynamic result)
        {
            // Converting the property name to lowercase
            // so that property names become case-insensitive.
            var name = binder.Name.ToLower();

            // If the property name is found in a dictionary,
            // set the result parameter to the property value and return true.
            // Otherwise, return false.
            return _dictionary.TryGetValue(name, out result);
        }

        // If you try to set a value of a property that is
        // not defined in the class, this method is called.
        public override bool TrySetMember(SetMemberBinder binder, Object value)
        {
            // Converting the property name to lowercase
            // so that property names become case-insensitive.
            _dictionary[binder.Name.ToLower()] = value;

            // You can always add a value to a dictionary,
            // so this method always returns true.
            return true;
        }

        #endregion

        #region Convenience Methods

        // Convenience methods that alias Console.WriteLine to something shorter.
        public static void P() { { Console.WriteLine(); } }
        public static void P(Boolean s) { { Console.WriteLine(s); } }
        public static void P(Char c) { { Console.WriteLine(c); } }
        public static void P(Char[] c) { { Console.WriteLine(c); } }
        public static void P(Decimal d) { { Console.WriteLine(d); } }
        public static void P(Double dd) { { Console.WriteLine(dd); } }
        public static void P(Int32 i) { { Console.WriteLine(i); } }
        public static void P(Int64 i64) { { Console.WriteLine(i64); } }
        public static void P(Object o) { { Console.WriteLine(o); } }
        public static void P(Single s) { { Console.WriteLine(s); } }
        public static void P(String s) { { Console.WriteLine(s); } }
        public static void P(UInt32 ui32) { { Console.WriteLine(ui32); } }
        public static void P(UInt64 ui64) { { Console.WriteLine(ui64); } }
        public static void P(String s, Object o) { { Console.WriteLine(s, o); } }
        public static void P(String s, params Object[] o) { { Console.WriteLine(s, o); } }
        public static void P(Char[] c, Int32 x, Int32 y) { { Console.WriteLine(c, x, y); } }
        public static void P(String s, Object x, Object y) { { Console.WriteLine(s, x, y); } }
        public static void P(String s, Object x, Object y, Object z) { { Console.WriteLine(s, x, y, z); } }
        public static void P(String s, Object w, Object x, Object y, Object z) { { Console.WriteLine(s, w, x, y, z); } }

        #endregion

    }
}
